const fs = require('fs');
const { createCanvas } = require('canvas');

// 创建占位图标
function createPlaceholderIcon(name, outputPath) {
  // 创建60x60像素的画布
  const canvas = createCanvas(60, 60);
  const ctx = canvas.getContext('2d');
  
  // 填充背景
  ctx.fillStyle = '#f5f5f5';
  ctx.fillRect(0, 0, 60, 60);
  
  // 绘制边框
  ctx.strokeStyle = '#cccccc';
  ctx.lineWidth = 2;
  ctx.strokeRect(2, 2, 56, 56);
  
  // 绘制图标名称
  ctx.fillStyle = '#333333';
  ctx.font = '10px Arial';
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';
  
  // 分割文本以适应图标
  const words = name.split('-');
  for (let i = 0; i < words.length; i++) {
    ctx.fillText(words[i], 30, 30 - 5 + (i * 12));
  }
  
  // 将画布导出为PNG
  const buffer = canvas.toBuffer('image/png');
  fs.writeFileSync(outputPath, buffer);
  
  console.log(`创建图标: ${outputPath}`);
}

// 要创建的图标列表
const icons = [
  { name: 'beauty-course', path: './images/icons/beauty-course.png' },
  { name: 'member-benefits', path: './images/icons/member-benefits.png' },
  // 添加其他需要的图标
];

// 创建图标
icons.forEach(icon => {
  createPlaceholderIcon(icon.name, icon.path);
});

console.log('图标创建完成'); 